/**
 * 存储localStorage
 */
export const setStore = (name, content) => {
    if (!name) return
    if (typeof content !== 'string') {
      content = JSON.stringify(content)
    }
    window.localStorage.setItem(name, content)
  }
  
  /**
   * 获取localStorage
   */
  export const getStore = name => {
    if (!name) return
    return window.localStorage.getItem(name)
  }
  
  /**
   * 删除localStorage
   */
  export const removeStore = name => {
    if (!name) return
    window.localStorage.removeItem(name)
  }
  
  /**
   * 时间戳转日期 yyyy-mm-dd
   */
  export const format = date => {
    if (!date) return
    let sDate = new Date(date)
    let year = sDate.getFullYear()
    let month = (sDate.getMonth() + 1).toString().length < 2 ? `0${sDate.getMonth() + 1}` : sDate.getMonth() + 1
    let day = sDate.getDate().toString().length < 2 ? `0${sDate.getDate()}` : sDate.getDate()
    // let hour = now.getHours()
    // let minute = now.getMinutes()
    // let second = now.getSeconds()
    return `${year}-${month}-${day}`
  }
  
  /**
   * 时间戳转日期 yyyy-mm-dd hh:mm
   */
  export const formatHM = date => {
    if (!date) return
    let sDate = new Date(date)
    let year = sDate.getFullYear()
    let month = (sDate.getMonth() + 1).toString().length < 2 ? `0${sDate.getMonth() + 1}` : sDate.getMonth() + 1
    let day = sDate.getDate().toString().length < 2 ? `0${sDate.getDate()}` : sDate.getDate()
    let hour = sDate.getHours().toString().length < 2 ? `0${sDate.getHours()}` : sDate.getHours()
    let minute = sDate.getMinutes().toString().length < 2 ? `0${sDate.getMinutes()}` : sDate.getMinutes()
    // let second = sDate.getSeconds()
    return `${year}-${month}-${day} ${hour}:${minute}`
  }
  
  /**
   * 时间戳转日期 yyyy-mm-dd hh:mm:ss
   */
  export const formatHMS = date => {
    if (!date) return
    let sDate = new Date(date)
    let year = sDate.getFullYear()
    let month = (sDate.getMonth() + 1).toString().length < 2 ? `0${sDate.getMonth() + 1}` : sDate.getMonth() + 1
    let day = sDate.getDate().toString().length < 2 ? `0${sDate.getDate()}` : sDate.getDate()
    let hour = sDate.getHours().toString().length < 2 ? `0${sDate.getHours()}` : sDate.getHours()
    let minute = sDate.getMinutes().toString().length < 2 ? `0${sDate.getMinutes()}` : sDate.getMinutes()
    let second = sDate.getSeconds().toString().length < 2 ? `0${sDate.getSeconds()}` : sDate.getSeconds()
    return `${year}-${month}-${day} ${hour}:${minute}:${second}`
  }
  
  /**
   * 时间戳转日期  今天的日期为数组00：00：00   23：59：59  yyyy-mm-dd hh:mm:ss (查询初始化到具体秒的数据)
   */
  export const formatToday = () => {
    let today = []
    let startTime = new Date(new Date().toLocaleDateString()).getTime()
    let endTime = new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1
    startTime = formatHMS(startTime)
    endTime = formatHMS(endTime)
    today.push(startTime)
    today.push(endTime)
    return today
  }
  
  /**
   * 获取url后面参数
   */
  export const GetQueryString = (name) => {
    let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
    // var r = window.location.search.substr(1).match(reg)
    let url = location.href
    url = url.substring(url.indexOf('?') + 1, url.length)
    var r = url.match(reg)
    if (r != null) {
      return unescape(r[2])
    }
    return ''
  }
  
  